package cn.edu.ctbu.myblog.dao;

import cn.edu.ctbu.myblog.domain.CommentDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface CommentDAO extends Mapper<CommentDO>{
    @Select("SELECT\n" +
            "`comment`.id AS id,\n" +
            "`comment`.userId AS userId,\n" +
            "`comment`.articleId AS articleId,\n" +
            "`comment`.`comment` AS `comment`,\n" +
            "`comment`.createCommentTime AS createCommentTime,\n" +
            "`user`.userName AS userName\n" +
            "FROM\n" +
            "`comment`\n" +
            "LEFT JOIN `user` ON `user`.id = `comment`.userId")

    public List<CommentDO> findAll();

    @Select("select * from comment where id=#{id}")
    public List<CommentDO> findById(int id);

    @Insert("insert into comment(userId,articleId,comment,createCommentTime) values (#{userId},#{articleId},#{comment},#{createCommentTime})")
    public void addComment(int userId, int articleId, String comment, Date createCommentTime);

}